package com.jiutong.meipenggang.http.present;

import android.content.Context;
import android.text.format.Time;

import com.jiutong.meipenggang.common.Constants;
import com.jiutong.meipenggang.entity.BaseBean;
import com.jiutong.meipenggang.http.model.interfaces.BindingBankCardBiz;
import com.jiutong.meipenggang.http.model.requests.BindingBankCardRequest;
import com.jiutong.meipenggang.http.subscribers.ProgressSubscriber;
import com.jiutong.meipenggang.http.subscribers.SubscriberOnNextListener;
import com.jiutong.meipenggang.utils.SpConfig;
import com.jiutong.meipenggang.utils.TimeUitl;

import java.util.HashMap;


/**
 * Created by Veken on 2017/5/27.
 */

public class BindingBankCardPresent {

    private final Context mContext;
    private final BindingBankCardBiz bindingBankCardBiz;
    private final BindingBankCardRequest bindingBankCardRequest;

    public BindingBankCardPresent(Context context, BindingBankCardBiz bindingBankCardBiz) {
        this.mContext = context;
        this.bindingBankCardBiz = bindingBankCardBiz;
        this.bindingBankCardRequest = new BindingBankCardRequest();
    }

    /**
     * 绑定银行卡
     */
    public void bindingBankCard() {

        SubscriberOnNextListener onNextListener = new SubscriberOnNextListener<BaseBean>() {
            @Override
            public void onNext(BaseBean subjects) {
                bindingBankCardBiz.onSuccess(subjects);
            }

            @Override
            public void onError(Throwable e) {
                bindingBankCardBiz.onError(e);
            }
        };

        HashMap<String, Object> fieldsMap = new HashMap<>();
        fieldsMap.put("OPT",bindingBankCardBiz.getOpt());
        fieldsMap.put("cardPhone", bindingBankCardBiz.getPhoneNum());
        fieldsMap.put("bankCardNum",bindingBankCardBiz.getBankCardNum());
        fieldsMap.put("idNumber",bindingBankCardBiz.getIdCard());
        fieldsMap.put("realName",bindingBankCardBiz.getBankName());
        fieldsMap.put("provinceCode",bindingBankCardBiz.getProvinceCode());
        fieldsMap.put("cityCode",bindingBankCardBiz.getCityCode());
        fieldsMap.put("timestamp", TimeUitl.getDate());
        fieldsMap.put("id", SpConfig.getInstance().getString(Constants.ID));
        fieldsMap.put("token",SpConfig.getInstance().getString(Constants.TOKEN));


        bindingBankCardRequest.bindingBankCard(new ProgressSubscriber(onNextListener, mContext), fieldsMap);
    }

}
